<?xml version="1.0" encoding="utf-8" ?> 
<sqlMap namespace="User"
	xmlns="http://ibatis.apache.org/mapping" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<alias>
		<typeAlias alias="User" type="Domain.User" />
	</alias>

	<resultMaps>
		<resultMap id="FullResultMap" class="User">
			<result property="userId" column="userId" dbType="Int"/>
      <result property="userCode" column="userCode" dbType="NVarChar"/>
      <result property="userName" column="userName" dbType="NVarChar"/>
			<result property="password" column="password" dbType="NVarChar"/>
			<result property="email" column="email" dbType="NVarChar"/>
			<result property="sex" column="sex" dbType="Int"/>
			<result property="provinceId" column="provinceId" dbType="Int"/>
			<result property="cityId" column="cityId" dbType="Int"/>
			<result property="identityCard" column="identityCard" dbType="VarChar"/>
			<result property="postCode" column="postCode" dbType="Int"/>
			<result property="addressCorp" column="addressCorp" dbType="NVarChar"/>
			<result property="addressFactory" column="addressFactory" dbType="NVarChar"/>
			<result property="telephone" column="telephone" dbType="NVarChar"/>
			<result property="mobile" column="mobile" dbType="NVarChar"/>
			<result property="trueName" column="trueName" dbType="NVarChar"/>
			<result property="duty" column="duty" dbType="NVarChar"/>
			<result property="GUID" column="GUID" dbType="NVarChar"/>
			<result property="regDate" column="regDate" dbType="SmallDateTime"/>
		</resultMap>
	</resultMaps>
	
	<statements>

		<select id="GetCount" resultClass="System.Int32">
			SELECT count(*) FROM [dbo].[user]
		</select>
		
		<select id="GetCountByCondition" parameterClass="Hashtable" resultClass="System.Int32" extends="GetCount">
			WHERE $condition$
		</select>
		
		<select id="FindAll" resultClass="User">
			SELECT * 
			FROM [dbo].[user]
		</select>
		
		<select id="GetModel" parameterClass="User" resultClass="User" extends="FindAll">
			WHERE
				([user].[userId] = #userId,dbType=Int#)
		</select>

    <select id="GetModelWhenLogin" parameterClass="hashtable" resultClass="User" extends="FindAll">
      where userName=#userName# and password=#password#
    </select>
    
		<insert id="Insert" parameterClass="User">
      INSERT INTO [dbo].[user] (
      [userCode],
      [userName] ,
      [password] ,
      [email] ,
      [sex] ,
      [provinceId] ,
      [cityId] ,
      [identityCard] ,
      [postCode] ,
      [addressCorp] ,
      [addressFactory] ,
      [telephone] ,
      [mobile] ,
      [trueName] ,
      [duty] ,
      [GUID] ,
      [regDate]
      ) VALUES (
      #userCode,dbType=NVarChar# ,
      #userName,dbType=NVarChar# ,
      #password,dbType=NVarChar# ,
      #email,dbType=NVarChar# ,
      #sex,dbType=Int# ,
      #provinceId,dbType=Int# ,
      #cityId,dbType=Int# ,
      #identityCard,dbType=VarChar# ,
      #postCode,dbType=Int# ,
      #addressCorp,dbType=NVarChar# ,
      #addressFactory,dbType=NVarChar# ,
      #telephone,dbType=NVarChar# ,
      #mobile,dbType=NVarChar# ,
      #trueName,dbType=NVarChar# ,
      #duty,dbType=NVarChar# ,
      #GUID,dbType=NVarChar# ,
      #regDate,dbType=SmallDateTime#
      )
    </insert>

    <select id="SelectUserExists" parameterClass="string" resultClass="int">
      select count(*) from [dbo].[user] where userName=#value#
    </select>
		<update id="Update" parameterClass="User">
			UPDATE [dbo].[user] SET
				  [password] = #password,dbType=NVarChar#
				, [email] = #email,dbType=NVarChar#
				, [sex] = #sex,dbType=Int#
				, [provinceId] = #provinceId,dbType=Int#
				, [cityId] = #cityId,dbType=Int#
				, [identityCard] = #identityCard,dbType=VarChar#
				, [postCode] = #postCode,dbType=Int#
				, [addressCorp] = #addressCorp,dbType=NVarChar#
				, [addressFactory] = #addressFactory,dbType=NVarChar#
				, [telephone] = #telephone,dbType=NVarChar#
				, [mobile] = #mobile,dbType=NVarChar#
				, [trueName] = #trueName,dbType=NVarChar#
				, [duty] = #duty,dbType=NVarChar#
				, [GUID] = #GUID,dbType=NVarChar#
				, [regDate] = #regDate,dbType=SmallDateTime#
			WHERE
				([userId] = #userId,dbType=Int#)
		</update>

		<delete id="Delete" parameterClass="User">
			DELETE FROM [dbo].[user]
			WHERE
				([userId] = #userId,dbType=Int#)
		</delete>

		<select id="GetModelsByCondition" parameterClass="Hashtable" resultClass="User">
			SELECT $columnNames$ FROM [dbo].[user] where $condition$
		</select>
		
		<select id="GetModelsByConditionByPager" parameterClass="Hashtable" resultClass="User">
      declare @indextable table(rno int identity(1,1),nid int)
      insert into @indextable(nid) select [userId] from [dbo].[user]
      where $condition$ order by $orderBy$

      select $columnNames$ from
      [dbo].[user] ,@indextable t
      <![CDATA[
			where t.nid= [user].userId and t.rno>#startNo# and t.rno<=#endNo# 
      order by t.rno asc
			]]>
		</select>
		
	</statements>
</sqlMap>
